/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bis;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/**
 *
 * @author Administrator
 */
public class FLBillMgr {

    public boolean buyBooks(FLShoppingCart cart, String username) {
        Collection items = cart.getItems();
        Iterator i = items.iterator();
        FLCustomer flc = new FLCustomer(username, username, username);
        ArrayList list = flc.getDatebyid();
        while (i.hasNext()) {
            FLShoppingCartItem sci = (FLShoppingCartItem) i.next();
            FLBook bd = (FLBook) sci.getItem();
            int quantity = sci.getQuantity();
            FLOrder order = new FLOrder(0, Double.parseDouble(((FLCustomer) list.get(0)).bm), bd.price * quantity, bd.price * quantity, 0, 0, "好");
            if (!order.isInsert()) {
                return false;
            }
            order.formname="tblOrders";
            int a=order.getmaxidbybm();
            int b=Integer.parseInt(bd.getBm());
            FLOrderMx ordermx = new FLOrderMx(a,b , bd.price * quantity, FLUtility.GetNowTime());
            if (!ordermx.Insert()) {
                return false;
            }

        }
        return true;
    }
}
